<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>webstorage本地数据存储</title>
		<script src="js/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function MyClick1(){
				var username=$("#txtUserName").val(); 
				var pwd=$("#txtPwd").val();
				//sessionStorage.setItem("k_username",username);
				//存储在浏览器缓存里，关闭浏览器就失去数据
				//sessionStorage.setItem("k_pwd",pwd);
				localStorage.setItem("k_username",username);
				//存储在本地文件里
				localStorage.setItem("k_pwd",pwd);
				alert("储存成功");
			}
			function MyClick2(){
				//alert(sessionStorage.getItem("k_username"));
				//alert(sessionStorage.getItem("k_pwd"));
				//localStorage.removeItem("k_username");
				//清除key值
				//localStorage.clear();
				//删除所有
				alert(localStorage.setItem("k_username"));
				alert(localStorage.setItem("k_pwd"));
			}
		</script>
	</head>
	<body>
		<input type="text" id="txtUserName" />
		<input type="password" id="txtPwd" />
		<input type="button" value="按钮1" onclick="MyClick1()" />
		<input type="button" value="按钮2" onclick="MyClick2()"/>
	</body>
</html>